<template>
  <view>
   <!-- <van-calendar :default-date="defaultDate" :show-title="false" :min-data="minDate" :max-date="maxDate" :show="showCalendar" :type="type" @confirm="onConfirm" color="#00BB93" :poppable="false" :show-confirm="showConfirm" class="calendar"> </van-calendar>
 -->
  </view>
</template>
<script>
import moment from "moment";
export default {
  data() {
    return {
      showCalendar: true,
      type: "single", //multiple 多个  range 时间区域  single 单个
      minDate: new Date().getTime(),
      maxDate: new Date().setMonth(new Date().getMonth() + Number(6)),
      showConfirm: false,
      defaultDate: "",
    };
  },
  onLoad: function (option) {
    let dt = new Date();
    // 上个页面把path拼接过来后期拼接url
    if (option.type) {
      this.type = option.type;
    }
    if (option.minDate) {
      this.minDate = option.minDate;
    } else {
      this.minData = dt.getTime();
    }
    if (option.maxDate) {
      this.maxDate = option.maxDate;
    } else {
      dt.setMonth(dt.getMonth() + Number(6));
      this.maxDate = dt.getTime();
    }
    if (option.showConfirm) {
      this.showConfirm = option.showConfirm;
    }
    dt = new Date();
    if (this.type == "range") {
      this.defaultDate = [];
      let startTime = new Date(option.startTime);
      let endTime = new Date(option.endTime);
      if (startTime && startTime.getTime() > dt.getTime()) {
        this.defaultDate.push(startTime);
      } else {
        this.defaultDate.push(dt);
      }
      if (endTime) {
        this.defaultDate.push(endTime);
        this.maxDate = Math.max(endTime.getTime(), this.maxDate);
      } else {
        dt.setTime(dt.getTime() + 24 * 60 * 60 * 1000);
        this.defaultDate.push(dt);
      }
    } else {
      if (option.defaultDate) {
        this.defaultDate = option.defaultDate;
      } else {
        this.defaultDate = dt.getTime();
      }
    }
  },
  methods: {
    onConfirm(date) {
      const eventChannel = this.getOpenerEventChannel();
      const detial = date.detail;
      if (detial instanceof Array) {
        let days = [];
        detial.forEach((day) => {
          days.push(moment(day).format("yyyy-MM-DD"));
        });
        eventChannel.emit("slectDate", days);
      } else {
        eventChannel.emit("slectDate", moment(detial).format("yyyy-MM-DD"));
      }
      uni.navigateBack({
        delta: 1,
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.calendar {
  height: 100vh;
  --calendar-height: 100vh;
  z-index: 2000;
}
</style>